package com.xuqm.sdhbwfu.app.ui

import android.content.Intent
import android.os.Bundle
import androidx.recyclerview.widget.GridLayoutManager
import com.xuqm.base.adapter.BasePagedAdapter
import com.xuqm.base.adapter.CommonPagedAdapter
import com.xuqm.base.adapter.ViewHolder
import com.xuqm.base.ui.BaseListFormLayoutActivity
import com.xuqm.sdhbwfu.app.R
import com.xuqm.sdhbwfu.app.common.PmTaskManage
import com.xuqm.sdhbwfu.app.databinding.ActivityPmTaskListBinding
import com.xuqm.sdhbwfu.app.model.PmTaskModel
import com.xuqm.sdhbwfu.app.viewmodel.PmTaskListViewModel

class PmTaskListActivity :
    BaseListFormLayoutActivity<PmTaskModel, PmTaskListViewModel, ActivityPmTaskListBinding>() {

    override fun getLayoutId(): Int = R.layout.activity_pm_task_list
    override fun fullscreen(): Boolean = true
    override fun adapter(): BasePagedAdapter<PmTaskModel> = adapter

    override fun initView(savedInstanceState: Bundle?) {
        super.initView(savedInstanceState)
        binding.inspectionBackLyt.setOnClickListener { finish() }
        binding.baseRecyclerView.layoutManager = GridLayoutManager(mContext, 3)
    }

//    var isFirst: Boolean = true
//    override fun onResume() {
//        super.onResume()
//        if (!isFirst)
//            viewModel.invalidate()
//        isFirst = false
//    }

    private val adapter: CommonPagedAdapter<PmTaskModel> =
        object : CommonPagedAdapter<PmTaskModel>(R.layout.item_pm_list) {
            override fun convert(
                holder: ViewHolder,
                item: PmTaskModel,
                position: Int
            ) {
                holder.setText(R.id.inspection_title, item.name)
                holder.setText(R.id.inspection_time, item.createTime)
                holder.gone(R.id.inspection_tag_tv)
                holder.gone(R.id.inspection_get_tv)
                holder.setClickListener(R.id.inspection_confirm_tv) {
                    PmTaskManage.title = item.name
                    PmTaskManage.firstCondition = item.firstCondition
                    PmTaskManage.firstId = item.id
                    PmTaskManage.safetyGuarantee = item.safetyGuarantee
                    PmTaskManage.toolPreparation = item.toolPreparation
                    PmTaskManage.materialPreparation = item.materialPreparation
                    PmTaskManage.stepMain = item.stepMain

                    startActivity(Intent(mContext, MaintainActivity::class.java))

                }
            }
        }


}